<?php
 class FlashAction extends CommonAction{
 	
      private  $table_name = "Flash";
	  function index(){
	  	if(isset($_POST['submit'])){
	  	    $data['title'] = $_POST['title'];
	  	    $data['url']=$_POST['url'];
	  	    $data['photo']=$this->upfile();
	  	    M('Flash')->add($data);
	  	    $this->success("发布成功");
	  		
	  	}else{
	  	 $this->list =M($this->table_name)->select();
	  	 $this->display();
	  	}
	  	
	  }

	  
	  //删除图片
	  function del(){
	  	
	  	 M($this->table_name)->where("id=".$_GET['id'])->delete();
	  	 $this->success("删除成功！");  
	  }
	  
	  
      function upfile(){
     
      	import('ORG.Net.UploadFile');
      	$path=date("Ym").'/';
      	$upload = new UploadFile();// 实例化上传类
      	$upload->maxSize  = 3145728 ;// 设置附件上传大小
      	$upload->allowExts  = array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
      	$upload->savePath =  './Data/photo/'.$path;// 设置附件上传目录
      	if(!file_exists("./Data/photo/".$path)){
      		mkdir("./Data/photo/".$path);
      	}
      	if(!$upload->upload()) {
      		// 上传错误提示错误信息
       
             return $upload->getErrorMsg();
      	}else{

      		$info = $upload->getUploadFileInfo(); //获取上传结果信息
      		$photopath= str_replace(".","",$info[0]['savepath']);
      		$s=$photopath.$info[0]['savename'];
      		
      		return $s;
     


      	}
      }

	  

	  	
      }
  

?>